package com.sc.nft.entity.vo;

import cn.hutool.core.util.StrUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.sc.nft.enums.EcologyPointsEnum;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.math.BigDecimal;
import java.util.Date;

@Data
public class AdminEcologyPointsUserWalletPageDetailsVO {

    @ApiModelProperty(value = "变更类型")
    private EcologyPointsEnum type;

    @ApiModelProperty(value = "变更类型名称")
    private String typeName;

    @ApiModelProperty(value = "金额")
    private String amount;

    @ApiModelProperty(value = "交易前余额")
    private String beforeBalance;

    @ApiModelProperty(value = "交易后余额")
    private String afterBalance;

    @ApiModelProperty(value = "备注")
    private String remark;

    @ApiModelProperty(value = "创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private Date createTime;

    @ApiModelProperty(value = "用户名")
    private String userName;

    @ApiModelProperty(value = "是否是增加")
    private Boolean isAdd;

    @ApiModelProperty(value = "操作人id")
    @JsonIgnore
    private Long createId;

    public void setUserName(String userName) {
        if(StrUtil.isBlank(userName)){
            this.userName = "系统";
            return;
        }

        this.userName = userName;
    }

    public void setType(EcologyPointsEnum type) {
        this.type = type;
        this.typeName = type.getDescription();
        this.isAdd = type.getIsAdd();
    }

    public void setAmount(BigDecimal amount) {
        this.amount = amount.setScale(2,BigDecimal.ROUND_DOWN).toPlainString();
    }

    public void setBeforeBalance(BigDecimal beforeBalance) {
        this.beforeBalance = beforeBalance.setScale(2,BigDecimal.ROUND_DOWN).toPlainString();
    }

    public void setAfterBalance(BigDecimal afterBalance) {
        this.afterBalance = afterBalance.setScale(2,BigDecimal.ROUND_DOWN).toPlainString();
    }
}
